﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Common.Forms
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void btnPrijaviSe_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(edtKorisnickoIme.Text))
            {
                this.erpLogin.SetError(edtKorisnickoIme, "Korisničko ime je obavezno!");
                this.DialogResult = DialogResult.None;
                return;
            }

            if (String.IsNullOrEmpty(edtLozinka.Text))
            {
                this.erpLogin.SetError(edtLozinka, "Lozinka je obavezna!");
                this.DialogResult = DialogResult.None;
                return;
            }

            using (CommonDataContext dc = new CommonDataContext())
            {
                var korisnik = dc.Korisniks.SingleOrDefault(c => c.KorisnickoIme == edtKorisnickoIme.Text);
                string lozinka = korisnik.Lozinka;

                if (!String.Equals(edtLozinka.Text, lozinka))
                {
                    this.erpLogin.SetError(edtLozinka, "Pogrešna lozinka!");
                    this.DialogResult = DialogResult.None;
                    return;
                }

                Common.Properties.Settings.Default.JezikId = korisnik.JezikId;
            }


        }
    }
}
